package cn.micai.base.thread;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/2/22 11:18
 */
public class VolatileThread extends Thread {

    private volatile boolean isRunning = true;

    private void setRunning(boolean isRunning){
        this.isRunning = isRunning;
    }

    @Override
    public void run() {
        System.out.println("进入run方法...");
        while (isRunning == true) {
            //..

        }
        System.out.println("线程停止...");
    }

    public static void main(String[] args) throws InterruptedException{
        VolatileThread vt = new VolatileThread();
        vt.start();
        Thread.sleep(3000);
        vt.setRunning(false);
        System.out.println("isRunning的值已经被设置了false");
        Thread.sleep(1000);
        System.out.println(vt.isRunning);
    }
}
